package com.itcast.tanhuasso.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

/**
 * @PachageName: com.itcast.tanhuasso.handle
 * @ClassName:
 * @Description: TODO
 * @Author: Hushi
 * @DateTime: 2021/2/720:19
 * @Version 1.0
 */
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object created = getFieldValByName("created", metaObject);
        if (created == null){
            setFieldValByName("created",new Date(),metaObject);
        }

        Object updated = getFieldValByName("updated", metaObject);
        if (created == null){
            setFieldValByName("updated",new Date(),metaObject);
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("updated",new Date(),metaObject);
    }
}
